<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('菜房订单--已生成订单但尚未出库的订单(待处理订单)')"/>
    <style>
        .fixed-table-toolbar .bs-bars {
            width: 100%;
        }

    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <!--<div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        &lt;!&ndash;菜房1&ndash;&gt;
                        <input type="hidden" name="cforderFor" value="1"/>
                        <input type="hidden" name="status" th:value="${status}"/>
                        <li>
                            订单类型：<select name="cforderType" th:with="type=${@dict.getType('cforderType')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            作物名称：<input type="text" name="cropNameCn"/>
                        </li>

                        <li>
                            作物品种：<input type="text" name="cropVarietiesCn"/>
                        </li>

                        <li class="select-time">
                            <label>需求时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>

                        <li>
                            状态：<select name="cforderStatus" th:with="type=${@dict.getType('cforderStatus')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>-->

        <div class="col-sm-12 search-collapse">
            <div class="btn-group " style="margin: 0px auto;display: table;" role="group">
                <button type="button" class="top-link btn btn-mini btn-primary">当天任务</button>
                <button type="button" class="top-link btn-sm btn-white">入库</button>
                <button type="button" class="top-link btn-sm btn-white">仓储</button>
                <button type="button" class="top-link btn-sm btn-white">出库</button>
            </div>


        </div>

        <div class="btn-group-sm" id="toolbar1" role="group">

            <h3 class="inline">待处理订单：</h3>
            <!--<a class="btn btn-success fl-r" onclick="$.operate.add()" shiro:hasPermission="system:ncCheck:add">
                <i class="fa fa-plus"></i> 新增检测
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
    <div class="bottom-btns"></div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncOrderCf:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncOrderCf:remove')}]];
    var prefix = ctx + "system/ncOrderCf";
    var datas = [[${@dict.getType('cforderType')}]];
    var cforderStatus = [[${@dict.getType('cforderStatus')}]];
    var normal_unit = [[${@dict.getType('normal_unit')}]];

    var cforderFor = [[${type}]]
    $(function () {
        var options = {
            url: prefix + "/listTodays?cforderStatus=1,2,3,4,5,6,7,8,9&status=2&cforderFor="+cforderFor,
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "菜房订单",
            pageSize: 1000,
            sidePagination: "client",
            toolbar: 'toolbar1',
            showExport: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            // queryParams: {cforderStatus: '1,2,3,4,5,6,7,8,9', status: '2', cforderFor: cforderFor},//未完成的所有订单&已生成订单的
            columns: [{
                title: '序号',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
                {
                    field: 'cforderCode',
                    title: '订单编号',
                    sortable: false
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                    sortable: false
                },
                {
                    field: 'cropVarietiesCn',
                    title: '作物品种',
                    sortable: false
                },
                /*{
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },*/
                {
                    field: 'requestTime',
                    title: '需求日期',
                    formatter: function (value, row, index) {
                        return dateFtt(value);
                    }
                },
                {
                    field: 'cforderId',
                    title: '菜房订单键',
                    visible: false
                },
                {
                    field: 'cforderType',
                    title: '订单类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },

                {
                    field: 'requestAmount',
                    title: '需求数量',
                    sortable: false
                },
                {
                    field: 'unit',
                    title: '单位',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(normal_unit, value);
                    }
                },

                {
                    field: 'cforderStatus',
                    title: '状态',
                    sortable: false,
                    formatter: function (value, row, index) {
                        /*蔬菜类状态：1、待分配，2、待检测，3、待入库，4、待出库，5、已完成
                        牛奶鸡蛋：6、牛舍待确认，7、鸡舍待确认，8、牛舍已确认，9、鸡舍已确认*/
                        return $.table.selectDictLabel(cforderStatus, value);
                    }
                },
                {
                    field: 'distribution',
                    title: '分配情况',
                    sortable: false,
                    formatter: function (value, row, index) {
                        if (1 == value) {
                            return "检测"
                        }
                        if (2 == value) {
                            return "仓储"
                        }
                        return "--";
                    }
                },
                {
                    field : 'remark',
                    title : '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        /*如果是牛舍或者鸡舍已确认*/
                        if (row.cforderStatus == 8 || row.cforderStatus == 9) {

                            if (row.cforderStatus == 8) {
                                actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="confirmCow(\'' + row.cforderId + '\')"><i class="fa fa-file"></i>确认</a>');

                            } else {
                                actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="confirm(\'' + row.cforderId + '\')"><i class="fa fa-file"></i>确认</a>');

                            }

                        } else

                        //1、待分配，2、待检测 两种状态才可以 去分配
                        if (row.cforderStatus == 1 || row.cforderStatus == 2) {

                            if (row.distribution == 1) {
                                actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="toStock(\'' + row.cforderId + '\')"><i class="fa fa-file"></i>分配仓储</a>');
                            } else if (row.distribution == 2) {
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="toCheck(\'' + row.cforderId + '\')"><i class="fa fa-check"></i>分配检测</a> ');
                            } else {
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="toCheck(\'' + row.cforderId + '\')"><i class="fa fa-check"></i>分配检测</a> ');
                                actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="toStock(\'' + row.cforderId + '\')"><i class="fa fa-file"></i>分配仓储</a>');

                            }
                            /*仓储的待出库的还可以再次分配*/
                        } else if (row.distribution == 2 && row.cforderStatus == 4) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="toCheck(\'' + row.cforderId + '\')"><i class="fa fa-check"></i>分配检测</a> ');

                        }


                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        var workType = cforderFor == 1 ? 4 : 5;
        var btns = [{
            name: '工作记录',
            url: ctx + 'system/ncNormalWorks?workType=' + workType,
            id: 'normal-work'
        }, {
            name: '运送登记',
            url: ctx + 'system/ncTransportInfo',
            id: 'yusong-dengji'
        },{
            name: '所有出库',
            url: ctx + 'system/ncOuputCf/ncOuputCfAll?type='+cforderFor,
            id: 'ncOuputCfAll'
        },{
            name: '当天出库汇总',
            url: ctx + 'system/ncOuputCf/ncOuputCfToday?date=&type='+cforderFor,
            id: 'ncOuputCfToday'
        }
        ]
        if (cforderFor != 1) {
            btns[1].hidden = 1;
        }
        addBtns(btns);


        $('.top-link').click(function () {
            var index = $(this).index();
            switch (index) {
                case 0:
                    window.location.reload();
                    return;
                case 1:
                    window.location.href = ctx + 'system/ncInputCf?type=' + cforderFor;
                    return;
                case 2:
                    window.location.href = ctx + 'system/ncInputCf/ncInputCf-stock?type=' + cforderFor;
                    return;
                case 3:
                    window.location.href = ctx + 'system/ncOuputCf?type=' + cforderFor;
                    return;
            }
        })
    });

    /*分配到检测*/
    function toCheck(id) {
        distribution('1', id, 2, "确认分配到检测吗？");
    }

    /*分配到仓储*/
    function toStock(id) {
        distribution('2', id, 4, "确认分配到仓储吗？");
    }

    /*牛舍/鸡舍确认*/
    function confirm(id) {
        var url = prefix + "/confirm/" + id;
        $.modal.open('菜房确认', url);
    }

    /*牛舍确认*/
    function confirmCow(id) {
        var msg = "确认收到牛奶？"
        var url = prefix + "/confirmCow";
        $.modal.confirm(msg, function () {
            myPost(url, {cforderId: id},
                function (data) {
                    if (data.code == 0) {
                        $.modal.msgSuccess(data.msg)
                    } else {
                        $.modal.msgError(data.msg)
                    }
                    reload()
                }, function (e) {
                    $.modal.msgError(data.msg)
                    reload()
                })
        });
    }


    function editSave(distribution, cforderId, cforderStatus, msg) {
        var confirmTable = prefix + "/edit";
        $.modal.confirm(msg, function () {
            myPost(confirmTable, {
                    distribution: distribution,
                    cforderId: cforderId,
                    cforderStatus: cforderStatus
                },
                function (data) {
                    if (data.code == 0) {
                        $.modal.msgSuccess(data.msg)
                    } else {
                        $.modal.msgError(data.msg)
                    }
                    reload()
                }, function (e) {
                    $.modal.msgError(data.msg)
                    reload()
                })

        })
    }

    function distribution(distribution, cforderId, cforderStatus, msg) {
        var confirmTable = prefix + "/distribution";
        $.modal.confirm(msg, function () {
            myPost(confirmTable, {
                    distribution: distribution,
                    cforderId: cforderId,
                    cforderStatus: cforderStatus
                },
                function (data) {
                    if (data.code == 0) {
                        $.modal.msgSuccess(data.msg)
                    } else {
                        $.modal.msgError(data.msg)
                    }
                    reload()
                }, function (e) {
                    $.modal.msgError(data.msg)
                    reload()
                })

        })
    }


    function reload() {
        $.table.refresh();
    }
    if(cforderFor == 1){
        setTitle("蔬菜整理间1-当天任务",false)
    }else {
        setTitle("蔬菜整理间2-当天任务",false)
    }
</script>
</body>
</html>